package com.ngc.mall.controller;

import com.ngc.mall.common.configure.response.ResponseResult;
import com.ngc.mall.dto.PermissionDTO;
import com.ngc.mall.param.PermissionParam;
import com.ngc.mall.service.IPermissionService;
import com.ngc.mall.vo.PermissionVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Resource
    private IPermissionService service;

    /**
     * 查看所有权限
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<List<PermissionVO>> selectAllPermission(){
        return ResponseResult.success(service.selectAllPermission());
    }

    /**
     * 新建权限
     * @param param
     * @return
     */
    @PostMapping("")
    public ResponseResult<Boolean> createPermission(@RequestBody PermissionParam param){
        System.out.println(param);
        PermissionDTO dto=PermissionDTO.builder().name(param.getName()).type(param.getType()).menuId(param.getMenuId()).build();
        return ResponseResult.auto(service.createPermission(dto));
    }



}
